package com.gs.common.exception;

import com.gs.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 杨光
 * @date 2021年08月12日 14:40
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public AjaxResult handleException(Exception e){
        e.printStackTrace();

        if(e instanceof CustomException){
            return AjaxResult.error(((CustomException) e).getCode(),e.getMessage());
        }

        return AjaxResult.error(500,"服务端异常，请联系管理员");
    }
}
